package com.primary.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.primary.controller.request.DonationsitesRequest;
import com.primary.entity.Donationsites;
import com.primary.mappers.DonationsitesMapper;
import com.primary.service.DonationsitesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("DonationsitesService")
public class DonationsitesServiceImpl implements DonationsitesService {

    @Autowired
    DonationsitesMapper donationsitesMapper;
    /**
     * 用于分页显示信息
     *
     * @param donationsitesRequest
     */
    @Override
    public PageInfo<Map<String, Object>> queryByPage(DonationsitesRequest donationsitesRequest) {
        PageHelper.startPage(donationsitesRequest.getPageNum(), donationsitesRequest.getPageSize());
        return new PageInfo<>(donationsitesMapper.listByPage(donationsitesRequest));
    }

    /**
     * 插入一条数据
     *
     * @param donationsites
     * @return
     */
    @Override
    public int insertOne(Donationsites donationsites) {
        return donationsitesMapper.insertOne(donationsites);
    }

    /**
     * 更新一条数据
     *
     * @param donationsites
     * @return
     */
    @Override
    public int updateOneById(Donationsites donationsites) {
        return donationsitesMapper.updateOneById(donationsites);
    }

    /**
     * 删除一条记录
     *
     * @param id
     * @return
     */
    @Override
    public boolean deleteById(Integer id) {
        return donationsitesMapper.deleteById(id) > 0;
    }

    /**
     * 方便前端选择信息
     *
     * @return
     */
    @Override
    public List<String> querySitesForSelecter() {
        return donationsitesMapper.querySitesForSelecter();
    }

    /**
     * 选择血液来源，供前端使用
     *
     * @return
     */
    @Override
    public List<String> querySitesAndCarsForSelecter() {
        return donationsitesMapper.querySitesAndCarsForSelecter();
    }
}
